package org.tech4j.common.core.sign.api;

import java.util.Objects;

/**
 * @program: tech4j-common
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/2 19:28
 **/
public class VerifyResult {
    private static final VerifyResult SUCCESS = new VerifyResult(true, "success");

    private final boolean success;

    private final String reason;

    private VerifyResult(final boolean success, final String reason) {
        this.success = success;
        this.reason = reason;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getReason() {
        return reason;
    }

    /**
     * Failure or not.
     *
     * @return true or false
     */
    public boolean isFailed() {
        return !success;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        VerifyResult that = (VerifyResult) o;
        return success == that.success && Objects.equals(reason, that.reason);
    }

    @Override
    public int hashCode() {
        return Objects.hash(success, reason);
    }

    /**
     * Generate failed verifyResult.
     *
     * @param reason The reason for the failure
     * @return verifyResult
     */
    public static VerifyResult fail(final String reason) {
        return new VerifyResult(false, reason);
    }

    /**
     * Generate successful verifyResult.
     *
     * @return verifyResult
     */
    public static VerifyResult success() {
        return SUCCESS;
    }
}
